<?php

namespace app\api\controller\web\frontend;

use app\common\controller\Api;
use think\facade\Db;

/**
 * banner接口.
 */
class Banner extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * banner列表
     */
    public function list()
    {
        // 展示条数
        $page = !empty(input('page')) ? input('page') : 1;
        $page_size = !empty(input('page_size')) ? input('page_size') : 10;

        // 所属页面
        $from = input('from') ?? '首页';
        
        $list = Db::name('web_banner')
                        ->field('tpic_image, href, smallpic_image,title,des')
                        ->where('fromlist', $from)
                        ->where('is_showswitch',1)
                        ->where('deletetime','=',null)
                        ->order('weigh desc, createtime desc')
                        ->limit($page_size)
                        ->select()
                        ->toArray();
        
        $count = Db::name('web_banner')->where('fromlist', $from)
                        ->where('is_showswitch',1)
                        ->where('deletetime','=',null)->count();

        $data = [
            'page'=>$page,
            'page_size'=>$page_size,
            'count'=>$count,
            'list'=>$list,
        ]; 

        $this->success('success',$data);
    }
}
